FROM --platform=linux/amd64 node:18.20.4

# 安装protoc编译环境
ARG PROTOBUF_VERSION=25.3
RUN apt-get update && apt-get install -y unzip wget protobuf-c-compiler python3-dev python3-pip
RUN wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip
RUN unzip protoc-${PROTOBUF_VERSION}-linux-x86_64.zip -d /usr/local

# 安装js的protobuf 编译环境
RUN npm install -g protobufjs-cli

# 安装Go和配置Golang protobuf编译环境
ARG GO_VERSION=1.21.7
RUN wget https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz
RUN tar -C /usr/local -zxvf go${GO_VERSION}.linux-amd64.tar.gz
ENV PATH="/usr/local/go/bin:$PATH"
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

# 安装nanopb编译环境
ARG NANOPB_TAG=0.4.8
RUN git clone --no-checkout https://github.com/nanopb/nanopb.git /nanopb && cd /nanopb && git checkout tags/${NANOPB_TAG} -b ${NANOPB_TAG}
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN pip3 install -r /nanopb/requirements.txt --break-system-packages

# 添加编译脚本
COPY build.sh /usr/local/bin/build.sh
RUN chmod +x /usr/local/bin/build.sh
